﻿using System.Collections.Generic;
using System.Data;
using System;
using FX.CC.Andon.Utility.DataBase;
using FX.CC.Andon.Entity.Version;

namespace FX.CC.Andon.Service.Version
{
    public class VersionService : DbHelperBase
    {
        public CEVersion GetLatestVersion(int clientType, out bool isExists)
        {
            CEVersion obj = new CEVersion();
            string sql = "Select Top 1 * From UT_CEVersion  Where ClientType=@1 Order By PubTime Desc";
            using (var cmd = Db.GetSqlStringCommond(sql))
            {
                Db.AddInParameter(cmd, "@1", DbType.Int32, clientType);
                try
                {
                    using (IDataReader reader = Db.ExecuteReader(cmd))
                    {
                        isExists = reader.Read();
                        if (isExists)
                        {
                            obj.VersionID = (Guid)reader[0];
                            obj.ClientType = clientType;
                            obj.PubTime = (DateTime)reader[2];
                        }
                    }
                }
                catch
                {
                    throw;
                }
            }
            return obj;
        }

    }
}
